
import groovy.grape.Grape
Grape.grab(group:"org.apache.camel", module:"camel-core", version:"2.0.0")
Grape.grab(group:"org.apache.camel", module:"camel-jetty", version:"2.0.0")

class HelloBean {
  public String sayHello(String body) {
    "Hello ${body}, nice going."
  }
  public String sayHelloToBoss(String body) {
    "Hello Boss."
  }
}

class MyRouteBuilder extends org.apache.camel.builder.RouteBuilder { 
  void configure() { 
    from("direct://foo").choice()
      .when(body().contains("Jack")).bean(HelloBean.class, "sayHelloToBoss")
      .otherwise().bean(HelloBean.class, "sayHello")
      .end().to("mock://result")
    // curl --data "name=Jack" http://localhost:8080/tutorial
    from('jetty:http://localhost:8080/tutorial').transform().simple("header.name").to("direct://foo")
  }
}

ctx = new org.apache.camel.impl.DefaultCamelContext()
mrb = new MyRouteBuilder()
ctx.addRoutes mrb
ctx.start()

p = ctx.createProducerTemplate()
p.sendBody("direct:foo", "Jack")
p.sendBody("direct:foo", "Peter")

e = ctx.getEndpoints("mock://result")[0]
e.exchanges.each { ex ->
  println "INFO> in.body='${ex.in.body}'"
}
